from sklearn.datasets import make_blobs
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier


def classification(train_feature, train_label, test_feature):
    '''
    使用KNeighborsClassifier对test_feature进行分类
    :param train_feature: 训练集数据
    :param train_label: 训练集标签
    :param test_feature: 测试集数据
    :return: 测试集预测结果
    '''

    md = KNeighborsClassifier()
    md.fit(train_feature, train_label.astype("int"))
    return md.predict(test_feature)


if __name__ == '__main__':
    X, Y = make_blobs(n_samples=100, centers=5, random_state=233)
    X_train, X_test, Y_train, Y_test = train_test_split(X, Y)
    predict = classification(X_train, Y_train, X_test)
    acc = accuracy_score(Y_test, predict)
    if acc > 0.75:
        print('你的准确率高于0.75')
    else:
        print('你的准确率为%.6f' % acc)
